function HandleMouseDown( event )
{
	MouseDown = true;
	LastMouseX = event.clientX;
	LastMouseY = event.clientY;
	WhichButton( event );
}

function HandleMouseUp( event )
{
	MouseDown = false;
}

function HandleMouseMove( event )
{
	if( ! MouseDown )
	{
		return;
	}
	var newX = event.clientX;
	var newY = event.clientY;

	var deltaX = newX - LastMouseX;
	var deltaY = newY - LastMouseY;

	if( Left )
	{
		var newModelMatrix = mat4.create( );
		mat4.identity( newModelMatrix );
		mat4.rotate( newModelMatrix, degToRad(deltaX / 2.), [0, 1, 0] );
		mat4.rotate( newModelMatrix, degToRad(deltaY / 2.), [1, 0, 0] );
		mat4.multiply( newModelMatrix, ModelMatrix, ModelMatrix );
	}

	LastMouseX = newX;
	LastMouseY = newY;
}

function WhichButton( event )
{
	var b = event.button;
	
	Left   = ( b == 0 );
	Middle = ( b == 1 );
	Right  = ( b == 2 );
}